package com.lolineet.result;

/**
 * Result
 *
 * @author YUKI.N
 * @version 1.0
 * @description
 * @date 2025/3/10 17:56
 */
public class Result<T> {

    private String code;

    private String msg;

    private T data;

    public static <T> Result<T> ok(ResultCode code) {
        Result<T> result = new Result<T>();
        result.setCode(code.getCode());
        return result;
    }

    public static <T> Result<T> ok(String msg) {
        Result<T> result = Result.ok(ResultCode.SUCCESS);
        result.setMsg(msg);
        return result;
    }

    public static <T> Result<T> ok(T data) {
        Result<T> result = Result.ok(ResultCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(IResultCode code){
        Result<T> result = new Result<T>();
        result.setCode(code.getCode());
        result.setMsg(code.getMsg());
        return result;
    }

    public static <T> Result<T> error(){
        Result<T> result = new Result<T>();
        result.setCode(ResultCode.SYSTEM_EXECUTION_ERROR.getCode());
        result.setMsg(ResultCode.SYSTEM_EXECUTION_ERROR.getMsg());
        return result;
    }

    public static <T> Result<T> error(String msg){
        Result<T> result = new Result<T>();
        result.setCode(ResultCode.SYSTEM_EXECUTION_ERROR.getCode());
        result.setMsg(msg);
        return result;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
